package com.bmd.backgroundmanger.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bmd.backgroundmanger.entity.UserAnswer;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 用户答题记录Mapper接口
 */
@Mapper
public interface UserAnswerMapper extends BaseMapper<UserAnswer> {

    /**
     * 根据用户ID查询答题记录（包含题目信息）
     */
    List<UserAnswer> selectByUserId(Integer userId);

    /**
     * 根据题目ID查询答题记录
     */
    @Select("SELECT * FROM user_answers WHERE question_id = #{questionId}")
    List<UserAnswer> selectByQuestionId(Integer questionId);

    /**
     * 查询用户正确答题数量
     */
    @Select("SELECT COUNT(*) FROM user_answers WHERE user_id = #{userId} AND is_correct = 1")
    Integer countCorrectAnswersByUserId(Integer userId);

    /**
     * 查询用户总答题数量
     */
    @Select("SELECT COUNT(*) FROM user_answers WHERE user_id = #{userId}")
    Integer countTotalAnswersByUserId(Integer userId);
} 